#include "BlockQueue.hpp"
#include <iostream>

template <class T>
void* Comsume(void* arg){
	BlockQueue<T>* bq = static_cast<BlockQueue<T>*>(arg);
	while(true){
		T data = bq->Pop();
		std::cout << "消费了一个数据: " << data << std::endl;
		sleep(1);
	}

	return nullptr;
}

template <class T>
void* Produce(void* arg){
	BlockQueue<T>* bq = static_cast<BlockQueue<T>*>(arg);
	while(true){
		int data = 10;
		bq->Equeue(data);
		std::cout << "生产了一个数据: " << data << std::endl;
		sleep(1);
	}

	return nullptr;
}

int main()
{
	BlockQueue<int>* bq = new BlockQueue<int>();
	pthread_t comsumer, producer;
	pthread_create(&comsumer, nullptr, Comsume<int>, (void*)bq);
	pthread_create(&producer, nullptr, Produce<int>, (void*)bq);

	pthread_join(comsumer, nullptr);
	pthread_join(producer, nullptr);

	return 0;
}